<?php


namespace App\Http\Controllers\System\Dictionary;

use App\Http\Controllers\Controller;
use App\Http\Requests\System\Dictionary\Callback\StoreRequest;
use App\Http\Searchs\System\Dictionary\CallbackSearch;
use App\Repositories\Callback;

class CallbackController extends Controller
{
    /**
     * @var Callback
     * @author luffyzhao@vip.126.com
     */
    private $callback;

    /**
     * CallbackController constructor.
     * @param Callback $callback
     * @author luffyzhao@vip.126.com
     */
    public function __construct(Callback $callback)
    {
        $this->callback = $callback;
    }

    /**
     * @param CallbackSearch $search
     * @return \Illuminate\Http\JsonResponse
     * @author luffyzhao@vip.126.com
     */
    public function index(CallbackSearch $search)
    {
        return $this->response($this->callback->paginate($search->toArray()));
    }

    /**
     * @param StoreRequest $request
     * @return \Illuminate\Http\JsonResponse
     * @author luffyzhao@vip.126.com
     */
    public function store(StoreRequest $request){
        return $this->response(
            $this->callback->create($request->only(['code', 'name']))
        );
    }
}